<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ taglib prefix='sec' uri='http://www.springframework.org/security/tags'%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head>
<script type="text/javascript" src="scripts/boot.js"></script>
</head>
<body style="border: 0px; margin: 0px; padding: 0px;width: 100%;height: 100%">
<div class="mini-toolbar" style="border-bottom:0;padding:0px;">
    <table style="width:100%;">
        <tr>
            <td>
            <sec:authorize url='/medical_platform_add.do'>
				<a class="mini-button" iconCls="icon-add" onclick="onAddPlatform('添加中心')">增加中心</a>
			</sec:authorize>
			<sec:authorize url='/medical_platform_edit.do'>
				<a class="mini-button" iconCls="icon-edit" onclick="onEditPlatform('编辑名称')">编辑</a>
			</sec:authorize>
			<sec:authorize url='/meidcal_platform_del.do'>
				<a class="mini-button" iconCls="icon-remove" onclick="onRemovePlatform()">删除</a>
			</sec:authorize>
            </td>
        </tr>
    </table>           
</div>
<div class="mini-fit" >
	<div id="datagrid1" class="mini-datagrid " idField="id" pageSize="20"
		url="platform_list_view.do" style="width:100%;height:100%;" allowCellSelect="true">
		<div property="columns">
			<div type="indexcolumn" headerAlign="center">#</div>
			<div field="name" width="100" headerAlign="center" renderer="onActionRenderer" align="center">名称</div>
			<div field="description" width="100" headerAlign="center" align="center">说明</div>
			<div field="createTime" width="100" allowSort="true" headerAlign="center" align="center">创建时间</div>
			<div field="updateTime" width="100" allowSort="true" headerAlign="center" align="center">修改时间</div>
		</div>
	</div>
</div>
<script type="text/javascript">
	mini.parse();
	var grid = mini.get("datagrid1");
	grid.reload();
	
	function onAddPlatform(title) {
	    mini.open({
	   		url: "medical_platform_add.do",
	   		allowResize:false,
           	title: title, width: 290, height: 300,
           	onload: function () {
               var iframe = this.getIFrameEl();
               var data = { action: "new"};
               iframe.contentWindow.SetData(data);
       		},
    	   	ondestroy: function (action) {
    	   		if(action == 'succ'){
    	   			mini.showMessageBox({
	                    title: "提示",
	                    showModal:false,
	                    iconCls: "mini-messagebox-info",
	                    message: "保存成功！",
	                    timeout: 3000,
	                    x: 'right',
	                    y: 'bottom'
	                });
    	   			grid.load();
    	   		}
            }
     	});
	}
		
	function onEditPlatform(title) {
	    var row = grid.getSelected();
	    if(row){
    		mini.open({
    	   		url: "medical_platform_edit.do",
    	   		allowResize:false,
               	title: title, width: 290, height: 300,
               	onload: function () {
                   var iframe = this.getIFrameEl();
                   var data = { row: row };
                   iframe.contentWindow.SetData(data);
          		},
	    	   	ondestroy: function (action) {
	    	   		if(action == 'succ'){
	    	   			mini.showMessageBox({
		                    title: "提示",
		                    showModal:false,
		                    iconCls: "mini-messagebox-info",
		                    message: "修改成功！",
		                    timeout: 3000,
		                    x: 'right',
		                    y: 'bottom'
		                });
		    	   		grid.load();
	    	   		}
                }
         	});
	    }else{
	    	mini.alert("请选择一个中心！");
	    }
	}
	
	function onRemovePlatform(e) {
	    var row = grid.getSelected();
	    if (row) {
   			mini.confirm("确定删除记录？", "确定？",
            	function (action) {
               		if (action == "ok") {
   						$.post('platform_include_group.do', {id: row.id}, function(data){
   							if(data.success == 'error'){
   								mini.alert("数据错误，id不能为空");
   							} else if(data.success == 'true'){
  								mini.alert("当前中心下有组，无法删除！");
   							}else{
   	    						$.post('meidcal_platform_del.do', {id: row.id}, function(data){
		   	    					if(data.success){
	 		   	    					mini.showMessageBox({
	 					                    title: "提示",
	 					                    showModal:false,
	 					                    iconCls: "mini-messagebox-info",
	 					                    message: "删除成功！",
	 					                    timeout: 3000,
	 					                    x: 'right',
	 					                    y: 'bottom',
	 					                });
 		   	    						grid.load();
		   	    					}else{
		   	    						mini.alert("id不能为空，删除失败！");
		   	    					}
		   	    				}, "json");
	  						}
   						}, "json");
               		}
   				}
       		);
	    }else{
	    	mini.alert("请选择一个中心！");
	    }
	}

</script>
</body>
</html>